﻿using Kaleida.ServiceMonitor.Framework;
using NUnit.Framework;

namespace Kaleida.UnitTests.Framework
{
    public class PercentageTests
    {
        [Test]
        public void TestTryParseWholePercentage()
        {
            Percentage p1;
            Assert.IsTrue(Percentage.TryParse("50%", out p1));
            Assert.AreEqual(50, p1.PercentValue);
            Assert.AreEqual(0.5m, p1.Value);
            Assert.AreEqual("50%", p1.ToString());
        }

        [Test]
        public void TestTryParseDecimalPercentage()
        {
            Percentage p1;
            Assert.IsTrue(Percentage.TryParse("1.2345%", out p1));
            Assert.AreEqual(1.2345m, p1.PercentValue);
            Assert.AreEqual(0.012345m, p1.Value);
            Assert.AreEqual("1.2345%", p1.ToString());
        }

        [Test]
        public void TestTryParseNonPercentage()
        {
            Percentage p1;
            Assert.IsFalse(Percentage.TryParse("abc", out p1));
            Assert.IsNull(p1);

            Percentage p2;
            Assert.IsFalse(Percentage.TryParse("12", out p2));
            Assert.IsNull(p2);
        }

    }
}
